#!/usr/bin/env bash

# Author:   Zhang Huangbin (michaelbibby <at> gmail.com)

#---------------------------------------------------------------------
# This file is part of iRedMail, which is an open source mail server
# solution for Red Hat(R) Enterprise Linux, CentOS, Debian and Ubuntu.
#
# iRedMail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iRedMail is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iRedMail.  If not, see <http://www.gnu.org/licenses/>.
#---------------------------------------------------------------------

# Variables for MySQL database server and related.

export MYSQL_FRESH_INSTALLATION='YES'

# If your host is "localhost" MySQL (the commandline tool 'mysql' as well)
# always tries to use the socket connection for speeding up things. If you
# enter "127.0.0.1" as hostname, MySQL uses the TCP connection.
export MYSQL_SERVER='localhost'
export MYSQL_PORT='3306'
export MYSQL_SOCKET='/var/lib/mysql/mysql.sock'
export MYSQL_ROOT_USER='root'

# Use lowercase variable name for IP address.
if [ X"${MYSQL_SERVER}" == X"localhost" ]; then
    export mysql_server='127.0.0.1'
else
    export mysql_server="${MYSQL_SERVER}"
fi

# MySQL config file.
if [ X"${DISTRO}" == X"RHEL" ]; then
    export MYSQL_MY_CNF='/etc/my.cnf'

    # RC script.
    export MYSQLD_INIT_SCRIPT='/etc/init.d/mysqld'

elif [ X"${DISTRO}" == X"UBUNTU" -o X"${DISTRO}" == X"DEBIAN" ]; then
    export MYSQL_MY_CNF='/etc/mysql/my.cnf'

    # RC script.
    export MYSQLD_INIT_SCRIPT='/etc/init.d/mysql'

else
    :
fi

# For virtual user query in Postfix, Dovecot.
export MYSQL_BIND_USER="${VMAIL_USER_NAME}"
export MYSQL_BIND_PW="$(${RANDOM_STRING})"

# For vmail database management.
export MYSQL_ADMIN_USER="${VMAIL_ADMIN_USER_NAME}"
export MYSQL_ADMIN_PW="$(${RANDOM_STRING})"

export MYSQL_INIT_SQL="${CONF_DIR}/mysql_init.sql"
export MYSQL_VMAIL_SQL="${CONF_DIR}/mysql_vmail.sql"

# MySQL database to store virtual hosts.
export VMAIL_DB='vmail'
export SAMPLE_SQL="${SAMPLE_DIR}/iredmail.sql"
